package com.raycloud.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.raycloud.dao.UserRelationDao;
import com.raycloud.dao.common.BaseDao;
import com.raycloud.domain.UserRelation;

public class UserRelationDaoImpl extends BaseDao implements UserRelationDao{

	public void insertUserRelation(UserRelation userRelation) {
		getSqlMapClientTemplate().insert("userRelation.insertUserRelation", userRelation);
	}

	@SuppressWarnings("unchecked")
	public List<UserRelation> queryAllFans(String dbId, long userId) {
		Map<String, Object> codition = new HashMap<String, Object>();
		codition.put("dbId", dbId);
		codition.put("userId", userId);
		return getSqlMapClientTemplate().queryForList("userRelation.queryAllFans", codition);
	}

	public UserRelation getUserRelation(String dbId, long userId, long followId, int type) {
		Map<String, Object> codition = new HashMap<String, Object>();
		codition.put("dbId", dbId);
		codition.put("userId", userId);
		codition.put("followId", followId);
		codition.put("type", type);
		return (UserRelation) getSqlMapClientTemplate().queryForObject("userRelation.getUserRelation", codition);
	}

	public boolean isExist(String dbId, long userId, long followId) {
		Map<String, Object> codition = new HashMap<String, Object>();
		codition.put("dbId", dbId);
		codition.put("userId", userId);
		codition.put("followId", followId);
		Integer result = (Integer) getSqlMapClientTemplate().queryForObject("userRelation.queryIsExist", codition);
		if(result != null && result.intValue() > 0) {
			return true;
		}
		return false;
	}

	public void updateUserRelation(UserRelation userRelation) {
		getSqlMapClientTemplate().update("userRelation.updateUserRelation", userRelation);
	}
	
}
